package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.entities.CommonResult;
import com.atguigu.springcloud.entities.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
@Slf4j
@RequestMapping("/consumer")
public class OrderController {
    private static final String PAYMENT_URL = "http://localhost:8001/";
    @Resource
    private RestTemplate restTemplate;

    @PostMapping("/payment/create")
    public CommonResult create(Payment payment){
        /*
            postForObject()：会发送post请求访问对应的微服务的方法
         */
        return restTemplate.postForObject(PAYMENT_URL + "payment/create",payment,CommonResult.class);
    }

    @GetMapping("/payment/get/{id}")
    public CommonResult getPaymentById(@PathVariable Long id){
        /*
            调用远程的订单模块的getPaymentById()方法
         */
        return restTemplate.getForObject(PAYMENT_URL + "payment/get/"+id,CommonResult.class);
    }
}
